import sys

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QLayout

from Ui_externcommandlist import Ui_Form_externCommandList
from CommandList import CommandList


class ExternCommandList(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Form_externCommandList()
        self.ui.setupUi(self)
        # 创建一个列表，用于存放所有的CommandList,根据tab的个数添加widget
        self.commandList = [CommandList().Command_List_Widget for i in range(0, self.ui.tabWidget.count())]
        self.setUi()

    def setUi(self):
        # 根据tab的个数添加widget
        for i in range(0, self.ui.tabWidget.count()):
            self.ui.tabWidget.setCurrentIndex(i)
            layout = QtWidgets.QHBoxLayout()
            layout.setSpacing(0)
            layout.setContentsMargins(0, 0, 0, 0)
            layout.setStretch(0, 0)
            layout.setSizeConstraint(QLayout.SetFixedSize)
            layout.addWidget(self.commandList[i])
            self.ui.tabWidget.currentWidget().setLayout(layout)
            self.ui.tabWidget.currentWidget().setFixedSize(400, 770)


QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QtWidgets.QApplication(sys.argv)
window = ExternCommandList()
window.show()
sys.exit(app.exec_())
